using System;
using System.Collections.Generic;
using System.Text;
using Hermes.Framework;
using Hermes.Framework.FileSystem;

namespace Hermes.Framework.Implementation
{
    public class SimpleTransactionOperationFactory
    {
        protected IResourceManager resourceManager = null;

        protected INonTransactableFileSystemFactory fileSystemFactory = null;

        #region ITransactableOperationFactory Members

        public IResourceManager ResourceManager
        {
            set { this.resourceManager = value; }
        }

        public INonTransactableFileSystemFactory FileSystemFactory
        {
            set { this.fileSystemFactory = value; }
        }

        public ITransactableOperation GetOperation<T>(string fileName) where T : ITransactableOperation
        {
            ITransactableOperation operation = (ITransactableOperation)typeof(T).GetConstructor(new System.Type[] { typeof(string) }).Invoke(new object[] { fileName });
            operation.ResourceManager = this.resourceManager;
            operation.FileSystem = this.fileSystemFactory.GetFileSystem(fileName);

            return operation;
        }

        public ITransactableOperation GetOperation<T>(string from, string to) where T : ITransactableOperation
        {
            ITransactableOperation operation = (ITransactableOperation)typeof(T).GetConstructor(new System.Type[] { typeof(string), typeof(string) }).Invoke(new object[] { from, to });
            operation.ResourceManager = this.resourceManager;
            operation.FileSystem = this.fileSystemFactory.GetFileSystem(from, to);

            return operation;
        }

        #endregion
    }
}
